// 导入request
import http from "@utils/request";
import type { IRes } from "@interface";

interface IPackageData extends IRes {
  data: IPackageItem[];
}
export interface IPackageItem {
  id: string;
  tokensTitle: string; //充值标题
  detail: null;
  price: number; //充值金额
  amount: number; //充值量
  stock: number;
  status: number; // 状态.1-在售 2-下架 3-删除
  createTime: string;
  updateTime: string;
}
// 查询充值套餐
export const getpackage = () =>
  http.get<IPackageData>("/xlx-sso/account/getpackage");

interface IAliWxPayCode extends IRes {
  data: {
    codeUrl: string;
    orderNo: number;
  };
}

// 支付套餐-支付宝二维码
export const getAlipayCode = (tokensPriceId: string) =>
  http.get<IAliWxPayCode>(
    `/xlx-sso/alipay/scanPay?tokensPriceId=${tokensPriceId}`
  );

// 支付套餐-微信二维码
export const getWxCodeApi = (tokensPriceId: string) =>
  http.get<IAliWxPayCode>(
    `/xlx-sso/wxpay/native?tokensPriceId=${tokensPriceId}`
  );

export interface IOrderItem {
  id: string;
  orderNo: number; //支付单号
  userId: number;
  payment: number;
  paymentType: number;
  tokensPriceId: number;
  status: number; //  订单状态:0-已取消-10-未付款，20-已付款 30-交易关闭
  paymentTime: string;
  endTime: string;
  closeTime: null;
  createTime: string;
  updateTime: string;
  wxCodeUrl: string;
}
interface IOrderData extends IRes {
  data: IOrderItem;
}

// 查询支付订单
export const orderStatus = (orderNo: number) =>
  http.get<IOrderData>(`/xlx-sso/tokensOrder/get`, { orderNo });

interface IAccountQuota extends IRes {
  data: {
    created: string;
    updated: string;
    totalQuota: number; // 总额度
    usedQuota: number; //已使用额度
    currentBalance: number; //当前余额
  };
}
// 用户账户总额度查询
export const getAccountQuota = () =>
  http.get<IAccountQuota>("/xlx-sso/account/getAccountQuota");

export interface IAccountItem {
  created: string; // 创建时间
  updated: string; // 创建时间
  serialNumber: string; //流水号
  consumption: number; //消耗量
  remarks: string; //备注
  type: number; //类型0充值 1消耗
}
interface IAccountList extends IRes {
  data: {
    id: number;
    counts: number; //总条数
    pagesize: number; //每页显示数据
    pages: number; //总页数
    page: number; //第几页
    items: IAccountItem[];
  };
}

// 账户明细
export const getAccountList = (data: object) =>
  http.get<IAccountList>("/xlx-sso/account", data);
